package routers

import (
	"Walker/app/http/controller/api"
	"Walker/app/http/middleware"
	"github.com/gin-gonic/gin"
)

func InitApiRouter(router *gin.Engine) *gin.Engine {

	//处理跨域
	apiGroup := router.Group("/")
	{
		apiGroup.Use(middleware.Cross())

		//判断是否是调试模式启动开发包
		apiGroup.GET("/register", (&api.Login{}).Register)
		apiGroup.GET("/login", (&api.Login{}).Login)
		//路由设置
		User := apiGroup.Group("/user")
		{
			User.GET("/", (&api.User{}).Index)
			User.GET("/:id", (&api.Home{}).Show)
			User.DELETE("/:id", (&api.Home{}).Delete)
		}
		//并发抢购测试
		Test := apiGroup.Group("/")
		{
			Test.GET("/test/oversold", (&api.Test{}).Oversold)
			Test.GET("/test/oversold_queue", (&api.Test{}).OversoldQueue)
			Test.GET("/test/oversold_s_queue", (&api.Test{}).OversoldSQueue)
			Test.GET("/test/oversold_z_queue", (&api.Test{}).OversoldStrQueue)
			Test.GET("/test/snowflake", (&api.Test{}).Snowflake)
			Test.GET("/test/write", (&api.Test{}).Write)
		}
		//爬虫
		Reptile := apiGroup.Group("/")
		{
			Reptile.GET("/cli/start", (&api.Reptile{}).Start)
		}
		//rabbitmq相关实验
		Rabbit := apiGroup.Group("/rabbit")
		{
			Rabbit.GET("/index", (&api.Rabbit{}).Index)
		}
		//反射相关实验
		Reflect := apiGroup.Group("/reflect")
		{
			Reflect.GET("/index", (&api.Reflect{}).Index)
			Reflect.GET("/test", (&api.Reflect{}).Test)
		}
	}
	return router
}
